package com.ay277.htqoa.quartz.entity;

import org.hibernate.annotations.SourceType;

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

/**
 * Created by Temptation on 2016/12/23.
 */
public class TestMail {

    public static  void SendMail() throws Exception{

        //设置连接服务器
        Properties properties=System.getProperties();

        //设置邮件服务地址
        properties.put("mail.smtp.host","smtp.163.com");

        //设置邮件默认方式
        properties.put("mail.smtp.auth","true");//是否做身份验证
        properties.put("mail.smtp.port",465);//

        //设置邮件传输协议
        properties.put("mail.transport.protocol","smtp");
        //设置加密连接
        properties.put("mail.smtp.ssl.enable","true");
        properties.setProperty("mail.smtp.ssl.socketFactory","javax.net.ssh.SSLSocketFactory");
        //创建Session
        Session session=Session.getInstance(properties, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
               return new PasswordAuthentication("18932739291@163.com","lizhifei9054");
            }
        });

        //创建邮件
        MimeMessage message=new MimeMessage(session);
        InternetAddress from=new InternetAddress("18932739291@163.com");
        message.setFrom(from);
        InternetAddress to=new InternetAddress("tx_lizhifei@163.com");
        message.setRecipient(Message.RecipientType.TO,to);
        message.setSubject("ssh发送邮件");
        message.setText("您好啊    哈哈哈");
        //message.setSender(to);
        Transport.send(message);
        System.out.println("ok......");
    }
}
